<?php
/**
 * 公众号消息推送
 * User: Acer
 * Date: 2022/7/27
 * Time: 23:43
 */
namespace app\wx\service;

use app\wx\models\GzhSendMsgModel;

class GzhSendMsgService {
    // 获取发送的消息
    public function get_gzh_msg(){
        $GzhSendMsgModel =  new GzhSendMsgModel();
        $res = $GzhSendMsgModel->field("content")->where('state',1)->where('type',1)->order('sort')->select();
        if($res){
            return array_column($res, 'content');
        }
        return [];
    }
    public function s_get_msg(){
        $GzhSendMsgModel =  new GzhSendMsgModel();
        return $GzhSendMsgModel->select();
    }
    // 修改公众号消息
    public function s_modify_gzh_msg($data){
        $GzhSendMsgModel =  new GzhSendMsgModel();
        $updata = [
            'content'   =>  $data['content']
        ];
        if(isset($data['state'])) $updata['state'] = $data['state'];
        if(isset($data['sort'])) $updata['sort'] = $data['sort'];
        $GzhSendMsgModel->where('g_id',$data['g_id'])->update($updata);
    }

    // 删除消息
    public function s_del_gzh_msg($g_id){
        $GzhSendMsgModel =  new GzhSendMsgModel();
        return $GzhSendMsgModel->where('g_id',$g_id)->delete();
    }
    // 新增消息
    public function s_add_gzh_msg($data){
        $GzhSendMsgModel =  new GzhSendMsgModel();
        $updata = [
            'content'   =>  $data['content'],
        ];
        if(isset($data['state'])) $updata['state'] = $data['state'];
        if(isset($data['sort'])) $updata['sort'] = $data['sort'];
        return $GzhSendMsgModel->insert($updata);
    }
}